﻿
@{
    ViewData["Title"] = "List";
}

@section Scripts
    {
    <link href="~/css/page.css" rel="stylesheet" />
    <script src="~/echats/echarts.js"></script>
    <script>
        var selfLayer = null;
        layui.use(['layer', 'table', 'laydate'], function () {
            var layer = layui.layer, form = layui.form, //弹层
                table = layui.table; //表格

            picker.GetProvinceList(layui.form, { level: 1 }, "varProvince", {}); //省
            form.on("select(Province)", function (data) {
                axios.get('https://fishopeni.cnfm.com.cn:8095/api/Basis/GetAreaAll', {
                    params: {
                        level: 2,
                        code: data.value
                    }
                }).then(function (result) {
                    // console.log(result.data.result.data);
                    if (result.data.Code == 200) {
                        // $("#varCity").empty();
                        var options = '<option value="">请选择市</option>';
                        var resultdata = result.data.result.data;
                        if (resultdata != null) {
                            for (var i = 0; i < resultdata.length; i++) {
                                if (data.value == resultdata[i].yunCode)
                                    options += '<option value="' + resultdata[i].areaName + '" selected>' + resultdata[i].areaName + '</option>';
                                else
                                    options += '<option value="' + resultdata[i].areaName + '">' + resultdata[i].areaName + '</option>';
                            }
                        }
                        if ($("#City"))
                            $("#City").html(options);
                        if ($("#varCity"))
                            $("#varCity").html(options);
                        form.render();
                    } else {
                        alert(response.data.msg)
                    }

                }).catch(function (error) {
                    console.log(error);
                });


            })
            form.on("select(FishName)", function (data) {
                axios.get('https://fishopeni.cnfm.com.cn:8095/api/YSCBackstage/GetFingerlingTypeAll', {
                    params: {
                        fishType: data.value
                    }
                }).then(function (result) {
                    // console.log(result.data.result.data);
                    if (result.data.Code == 200) {
                        // $("#varCity").empty();
                        var options = '<option value="">请选择鱼类型</option>';
                        var resultdata = result.data.result;
                        console.log(result.data.result);
                        //  console.log(resultdata);
                        if (resultdata != null) {
                            for (var i = 0; i < resultdata.length; i++) {
                                if (data.value == resultdata[i].fishName)
                                    options += '<option value="' + resultdata[i].fishName + '" selected>' + resultdata[i].fishName + '</option>';
                                else
                                    options += '<option value="' + resultdata[i].fishName + '">' + resultdata[i].fishName + '</option>';
                            }
                        }
                        if ($("#Fish"))
                            $("#Fish").html(options);
                        if ($("#varFish"))
                            $("#varFish").html(options);
                        form.render();
                    } else {
                        alert(response.data.msg)
                    }

                }).catch(function (error) {
                    console.log(error);
                });


            })
            myEcharts();
        });



        function myEcharts() {
            //  alert($("#varTime").val());
            var myChart = echarts.init(document.getElementById("main"));
            var time = "";
            var timetype = "";
            $.get("/PlaceOfOriginPriceReport/GetPlaceOfOriginPriceTrendReport", { fishName: $("#varFish option:selected").val() == '' ? '鲢鱼' : $("#varFish option:selected").val(), province: $("#varProvince option:selected").val(), city: $("#varCity option:selected").val(), type: $("#varTime").val() }, function (result) {
                console.log(result);
                console.log(result.result);
                console.log("-----------");
                if (result.Code == "200") {
                    var resultdate = result.result.date;
                    var data = [];
                    var data1 = [];
                    var data4 = [];
                    // var data6 = [];
                    var data2 = ['地区', '全国'];
                    var data3 = [];
                    for (var i = 0; i < resultdate.area.length; i++) {
                        var namei = $.inArray(resultdate.area[i].day, data);
                        if (namei == -1) {
                            data.push(resultdate.area[i].day);
                            data1.push(resultdate.area[i].price);
                            data4.push(resultdate.national[i].price);
                        }
                    }
                    //for (var i = 0; i < resultdate.national.length; i++) {
                    //    var namei = $.inArray(resultdate.national[i].day, data6);
                    //    if (namei == -1) {
                    //        data4.push(resultdate.national[i].price);
                    //    }
                    //}

                    data3.push(data1);
                    data3.push(data4);
                    console.log("============");
                    console.log(data3);
                    var data5 = [];
                    for (var i = 0; i < data3.length; i++) {
                        data5.push({
                            name: data2[i],
                            data: data3[i],
                            type: 'bar'
                        })
                    }
                    console.log("====---------====");
                    console.log(data5);
                    option = {
                        color: ['#47F4F6', '#FF4DA4', '#A67EFF', '#FFCD57', '#63E3BB'],
                        title: {
                            text: '塘口价格分析',
                            x: 'center',
                            y: 10,
                        },
                        //legend: {
                        //    x: 'right',
                        //    data: ["本地","全国"],
                        //},
                        legend: {
                            textStyle: {
                                fontSize: 16
                            },
                            x: 'center',
                            y: 30,
                            data: data2
                        },
                        tooltip: {
                            trigger: 'axis'
                        },
                        toolbox: {
                            x: '85%',
                            y: 20,
                            feature: {
                                magicType: {
                                    show: true,
                                    type: ['line', 'bar'],
                                    title: { line: '折线图切换', bar: '柱形图切换' },
                                    iconStyle: {
                                        emphasis: {
                                            textPosition: 'top'
                                        }
                                    }
                                },
                                saveAsImage: {
                                    show: true, title: '下载', iconStyle: {
                                        emphasis: {
                                            textPosition: 'top'
                                        }
                                    }
                                }
                            },
                            textStyle: {//图例文字的样式
                            }
                        },
                        xAxis: {
                            name: '时间',
                            axisLabel: {
                                color: "#6793fe",
                                rotate: 60,
                                interval: 0
                            },
                            type: 'category',
                            data: data
                        },
                        yAxis: {
                            type: 'value',
                            name: '价格(/元)',
                            //axisLabel: {
                            //    color: "#fff",
                            //    formatter: '{value}'
                            //},
                            //axisLine: {    // 轴线
                            //    show: true,
                            //    lineStyle: {
                            //        color: '#fff',
                            //        type: 'dashed',
                            //        width: 1
                            //    }
                            //},
                            type: 'value'
                        },

                        series: data5
                    };
                    myChart.setOption(option);
                } else {
                    alert(result.msg);
                }
            });
        }
    </script>
}


<blockquote class="layui-elem-quote layui-text layui-form">
    <div class="layui-inline">
        <label class="layui-form-label">时间：</label>
        <div class="layui-input-inline">
            <select id="varTime" name="varTime" lay-filter="Time" autocomplete="off">
                <option value="0">一周</option>
                <option value="1">三个月</option>
                <option value="2">一年</option>
            </select>
        </div>
    </div>

    <div class="layui-inline">
        <label class="layui-form-label">鱼种类别：</label>
        <div class="layui-input-inline">
            <select id="varFishName" name="varFishName" lay-filter="FishName" autocomplete="off">
                @*<option value="">请选择鱼种类型</option>*@
                <option value="淡水鱼类">淡水鱼类</option>
                <option value="海藻类">海藻类</option>
                <option value="淡水其它类">淡水其它类</option>
                <option value="海水头足类">海水头足类</option>
                <option value="海水鱼类">海水鱼类</option>
                <option value="海水贝类">海水贝类</option>
                <option value="海水甲壳类">海水甲壳类</option>
                <option value="淡水甲壳类">淡水甲壳类</option>
            </select>
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">鱼种：</label>
        <div class="layui-input-inline">
            <select id="varFish" name="varFish" lay-filter="Fish" autocomplete="off">
                <option value="">请选择鱼种类型</option>
            </select>
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">省：</label>
        <div class="layui-input-inline">
            <select id="varProvince" name="varProvince" lay-filter="Province" autocomplete="off">
                <option value="">请选择省</option>
            </select>
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">市：</label>
        <div class="layui-input-inline">
            <select id="varCity" name="varCity" lay-filter="City" autocomplete="off">
                <option value="">请选择市</option>
            </select>
        </div>
    </div>
    <div class="layui-inline" style="width: 120px;">
        <div class="layui-form-label">
            <button class="layui-btn" id="search" style="width: 60px; height: 28px; line-height: 28px; display: inline" onclick="myEcharts()" data-type="reload">搜索</button>
        </div>
    </div>
</blockquote>
<table class="layui-table" id="dataview" lay-filter="datalist">
    <thead id="thdata"> </thead>
    <tbody id="tbdata"></tbody>
</table>

<br />
<div id="main" style="height: 600px; width: 98%"></div>

